﻿<Window x:Class="SQLDeploy.Builder.Controls.Environments.AddDialog"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:SQLDeploy.Builder.Controls.Environments"
        xmlns:c="clr-namespace:SQLDeploy.Builder.Converters"
        Title="Add Environment" Height="150" Width="300">
    <Window.Resources>
        <c:IsObjectNullConverter x:Key="IsNull"/>
        <BitmapImage x:Key="ErrorImage" UriSource="pack://siteoforigin:,,,/Resources/eventlogError.ico" />
        <Style x:Key="CustomTextBoxStyle" TargetType="TextBox">
            <Setter Property="Foreground" Value="Black"/>
            <Style.Triggers>
                
            </Style.Triggers>
        </Style>
        <ControlTemplate x:Key="TextBoxErrorTemplate" TargetType="Control">
            <Grid ClipToBounds="False">
                <Image HorizontalAlignment="Right" VerticalAlignment="Top"
                       Width="16" Height="16" Margin="0,-8, -8, 0"
                       Source="{StaticResource ErrorImage}"
                       ToolTip="{Binding ElementName=adornedElement,
                                        Path=AdornedElement.(Validation.Errors),
                                        Converter={c:ValidationErrorsToStringConverter}}" />
                <Border BorderBrush="Red" BorderThickness="1" Margin="-1">
                    <AdornedElementPlaceholder Name="adornedElement"/>
                </Border>
            </Grid>
        </ControlTemplate>
    </Window.Resources>
    <StackPanel Orientation="Vertical" Margin="8">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0" Grid.Column="0" Content="Environment name:"/>
            <TextBox Grid.Row="0" Grid.Column="1" x:Name="NameBox" Validation.ErrorTemplate="{StaticResource TextBoxErrorTemplate}">
                <TextBox.Text>
                    <Binding Path="Name" UpdateSourceTrigger="PropertyChanged">
                        <Binding.ValidationRules>
                            <local:ConnectionValidationRule/>
                        </Binding.ValidationRules>
                    </Binding>
                </TextBox.Text>
            </TextBox>

        </Grid>
        <StackPanel Orientation="Horizontal"  VerticalAlignment="Bottom" HorizontalAlignment="Right">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <Button Grid.Column="0" Margin="4"
                        IsEnabled="{Binding ElementName=NameBox, Path=BindingGroup.ValidationErrors, Converter={StaticResource IsNull}}"
                        
        			Content="Add" Click="Button_Click"/>
                <Button Grid.Column="1" Margin="4"
        			Content="Cancel" IsCancel="True"/>

            </Grid>
        </StackPanel>
    </StackPanel>
    
    
    
</Window>
